<template>
  <div class="app-page">
    <!-- app数据管理 页面分析 -->
    <el-row
      type="flex"
      justify="start">
      <el-date-picker
        v-model="searchParams.startTime"
        type="date"
        :editable="false"
        placeholder="开始日期"
        :picker-options="pickerOption0"
        format="yyyy-M-dd"
        value-format="yyyy-M-dd"
      />
      <span style="line-height: 36px;">~</span>
      <el-date-picker
        v-model="searchParams.endTime"
        type="date"
        :editable="false"
        placeholder="结束日期"
        format="yyyy-M-dd"
        value-format="yyyy-M-dd"
        :picker-options="pickerOption1"
      />
      <el-button
        type="primary"
        @click="handleSearch">
        搜索
      </el-button>
    </el-row>
    <el-table
      style="margin-top:20px;"
      :data="tableData"
      border
      v-loading="loading">
      <el-table-column
        prop="time"
        label="首次使用日期"
      />
      <el-table-column
        prop="allCounts"
        label="用户数"
      />
      <el-table-column
        align="center"
        label="存留率"
      >
        <el-table-column
          v-for="(item, index) in tableHead"
          :key="index"
          :prop="item"
          :label="`${index+1}周后`"
        />
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      :current-page="tablePage.currentPage"
      :page-sizes="[5, 10, 50]"
      :page-size="tablePage.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tablePage.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!-- <content>
      <el-row :gutter="40">
        <el-col :span="24">
          <CommonTable
            ref="userstaycounts"
            is-standard-data
            :table-head="[ { label: '首次使用日期', prop: 'browseCounts' }, { label: '用户数', prop: 'avgBroCountsPerDay' }, { label: '存留率', prop: 'avgBrowseTime' } ]"
            :search-params="searchParams"
            url="/api/midea/menu/analyse/userstaycounts"
            title="用户存留："
          />
        </el-col>
      </el-row>
    </content> -->
  </div>
</template>

<script>
// import CommonTable from '../components/CommonTable'

export default {
  // components: { CommonTable },
  data () {
    return {
      tableData: [],
      tableHead: [ 'oneRate', 'twoRate', 'threeRate', 'fouRate', 'fivRate', 'sixRate', 'sevRate' ],
      tablePage: {
        currentPage: 1,
        pageSize: 5,
        total: 0
      },
      loading: true,
      // showMore: false,
      // 搜索条件
      searchParams: {
        dayweekmonth: 0,
        endTime: '2019-08-20',
        startTime: '2018-07-20'
      },
      // 校验开始日期不能大于结束日期
      pickerOption0: {
        disabledDate: (time) => {
          if (this.searchParams.endTime !== '') {
            return time.getTime() > this.searchParams.endTime
          } else {
            return false
          }
        }
      },
      pickerOption1: {
        disabledDate: (time) => {
          if (this.searchParams.startTime !== '') {
            return time.getTime() < this.searchParams.startTime
          } else {
            return false
          }
        }
      }
    }
  },
  created () {
    this.handleSearch()
  },
  methods: {
    handleSearch () {
      this.tableData = []
      // this.tablePage.total = 0
      this.loading = true
      const params = Object.assign({
        currentPage: this.tablePage.currentPage,
        pageSize: this.tablePage.pageSize
      }, this.searchParams)
      const url = 'http://47.106.93.196:8200/cloud-menu/midea/menu/analyse/userstaycounts'
      this.$http.post(url, params).then(res => {
        this.loading = false
        this.tableData = res.data.data
        this.tablePage.total = res.data.data[0] ? res.data.data[0].total : ''
      }).catch(() => {
        this.loading = false
      })
    },
    // 分页组件控制
    handleSizeChange (val) {
      this.tablePage.pageSize = val
      this.handleSearch()
    },
    handleCurrentChange (val) {
      this.tablePage.currentPage = val
      this.handleSearch()
    }
  }
}
</script>

<style lang="scss">
</style>
